package com.lz.football.module.leagueMatch.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.club.vo.NpcClubInfoVo;
	import com.liangzhong.model.club.vo.TeamIconVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.LItem;
	import lz.controls.managers.TipsManager;

	/**
	 *队徽item 
	 * @author lake
	 * 
	 */	
	public class TeamIconItem extends LItem implements IComponent
	{
		/**
		 *队徽容器 
		 */		
		private var container :MovieClip;
		/**
		 *主 客 队标识
		 * 0 主队
		 * 1 客队 
		 */		
		private var hflag	   :int ;
		/**
		 *俱乐部id 
		 */		
		public var cid	   	   :int;
		/**
		 *tip显示 
		 */		
		private var tipObj    :Object ;
		/**
		 *显示标出自己 
		 */		
		private var selfFalgMc :MovieClip;
		/**
		 *段1 
		 */		
		private var line_one	:DisplayObject;
		/**
		 *段2
		 */		
		private var line_two	:DisplayObject;
		/**
		 *段3 
		 */		
		private var line_three	:DisplayObject;
		
		public function TeamIconItem()
		{
			super();
		}
		/**
		 *设置获取数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
			if(selfFalgMc && selfFalgMc.parent)
			{
				selfFalgMc.parent.removeChild(selfFalgMc);
			}
			if(line_one && line_one.parent)
			{
				line_one.parent.removeChild(line_one);
			}
			if(line_two && line_two.parent)
			{
				line_two.parent.removeChild(line_two);
			}
			if(line_three && line_three.parent)
			{
				line_three.parent.removeChild(line_three);
			}
			if(_data)
			{
				container.visible = true;
				var teamIconVec :Vector.<TeamIconVo> = AppData.getInstance().clubDatamanager.teamIconVec;
				var ramIndex :int = (teamIconVec.length) * Math.random();
				var tempTeam:TeamIconVo = teamIconVec[ramIndex];
				var iconDisp :DisplayObject = Reflection.createInstance(tempTeam.iconurl);
				if(iconDisp)
				{
					DisplayObjectUtil.removeAllChildren(container);
					container.addChild(iconDisp);
					iconDisp.x = (121 - iconDisp.width)/2;
				}
				if(hflag == 0)
				{
					cid = _data.hcid;
				}
				else
				{
					cid = _data.gcid;
				}
				var npcClubVo :NpcClubInfoVo = AppData.getInstance().npcClubManager.getNpcClubById(cid);
				if(npcClubVo != null)
				{
					tipObj = {};
					tipObj.desc = npcClubVo.descplay;
					tipObj.name = npcClubVo.name;
				}
				var chamSelfIndex :int = AppData.getInstance().leagueMatchManager.championMatchInfoVo.selfIndex;
				if(cid == AppData.getInstance().user.uid)
				{
					if(_data.selfIndex == chamSelfIndex)
					{
						_symbolSkin.parent.addChild(selfFalgMc);
						selfFalgMc.x = _symbolSkin.x - 4;
						selfFalgMc.y = _symbolSkin.y - 4;
					}
					tipObj = {};
					tipObj.desc = "本俱乐部强大无比";
					tipObj.name = AppData.getInstance().clubDatamanager.clubInfo.uname;
					//光线
					var lineCStr :String = "com.lz.football.league.res.line_";
					switch(_data.selfIndex)
					{
						case 1:
						{
							if(chamSelfIndex > 1)
							{
								line_one = Reflection.createInstance(lineCStr + 1 + "_" + hflag);
								_symbolSkin.parent.addChild(line_one);
								if(_data.wpos == 0)
								{
									line_one.scaleX = 1;
									if(_data.pos == 0)
									{
										line_one.x = _symbolSkin.x + 35;
										line_one.y = _symbolSkin.y +17;
									}
									else
									{
										line_one.x = _symbolSkin.x + 35;
										line_one.y = _symbolSkin.y - 4;
									}
								}
								else
								{
									line_one.scaleX = -1;
									if(_data.pos == 0)
									{
										line_one.x = _symbolSkin.x - 3;
										line_one.y = _symbolSkin.y +18;
									}
									else
									{
										line_one.x = _symbolSkin.x - 3;
										line_one.y = _symbolSkin.y - 2.5;
									}
								}
							}
							break;
						}
						case 2:
						{
							if(chamSelfIndex > 2)
							{
								line_two = Reflection.createInstance(lineCStr + 2 + "_" + hflag);
								_symbolSkin.parent.addChild(line_two);
								if(_data.wpos == 0)
								{
									line_two.scaleX = 1;
									if(_data.pos == 0)
									{
										line_two.x = _symbolSkin.x + 36;
										line_two.y = _symbolSkin.y +18;
									}
									else
									{
										line_two.x = _symbolSkin.x + 36;
										line_two.y = _symbolSkin.y - 15;
									}
								}
								else
								{
									line_two.scaleX = -1;
									if(_data.pos == 0)
									{
										line_two.x = _symbolSkin.x;
										line_two.y = _symbolSkin.y +14.7;
									}
									else
									{
										line_two.x = _symbolSkin.x;
										line_two.y = _symbolSkin.y - 28;
									}
								}
							}
							break;
						}
						case 3:
						{
							if(chamSelfIndex > 3)
							{
								line_three = Reflection.createInstance(lineCStr + 3 + "_" + hflag);
								_symbolSkin.parent.addChild(line_three);
								if(_data.wpos == 0)
								{
									line_three.scaleX = 1;
									if(_data.pos == 0)
									{
										line_three.x = _symbolSkin.x + 36;
										line_three.y = _symbolSkin.y +14;
									}
									else
									{
										line_three.x = _symbolSkin.x + 36;
										line_three.y = _symbolSkin.y - 57;
									}
								}
								else
								{
									line_three.scaleX = -1;
									if(_data.pos == 0)
									{
										line_three.x = _symbolSkin.x;
										line_three.y = _symbolSkin.y +13.5;
									}
									else
									{
										line_three.x = _symbolSkin.x;
										line_three.y = _symbolSkin.y - 58;
									}
								}
							}
							break;
						}
						case 4:
						{
							
							break;
						}
					}
				}
			}
			else
			{
				container.visible = false;
			}
		}
		override public function get data():*
		{
			return super.data;
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			_symbolSkin.buttonMode = true;
			hflag = _symbolSkin.name.split("_")[2];
			container = _symbolSkin.container;
			container.visible = false;
			selfFalgMc = Reflection.createInstance("com.football.leaguematch.view.selfFlagSkin");
			addEvtListener();
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		protected function onOverHandler(e :MouseEvent):void
		{
			if(tipObj == null)
			{
				return;
			}
			TipsManager.show(TipsConst.TEAMINFOTIPS,tipObj,15,15,true,true);
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		protected function onOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}